<?php

/**
* @copyright   (C) 2010 iJoomla, Inc. - All rights reserved.
* @license  GNU General Public License, version 2 (http://www.gnu.org/licenses/gpl-2.0.html) 
* @author  iJoomla.com webmaster@ijoomla.com
* @url   http://www.ijoomla.com/licensing/
* the PHP code portions are distributed under the GPL license. If not otherwise stated, all images, manuals, cascading style sheets, and included JavaScript  
* are NOT GPL, and are released under the IJOOMLA Proprietary Use License v1.0 
* More info at http://www.ijoomla.com/licensing/
*/

defined('_JEXEC') or die('Restricted access');

jimport('joomla.application.component.view');

class iJoomla_SurveysViewNewskip extends JView {
	
	function display($tpl = null){				
		JToolBarHelper::title(JText::_('COM_SURVEYS_SURVEY'));
		JToolBarHelper::save();
		JToolBarHelper::apply();
		JToolBarHelper::cancel();
		JToolBarHelper::divider();
		JToolBarHelper::help('com_surveys',true);
					
		$this->values = $this->get("SkipValues");
		$this->columnsValues = $this->get("ColumnsValues");				
			
		parent::display($tpl);	
	}
		
	function getSurveysList($default){
		$result = $this->get("AllSurveys");
		$selected = "";
		$return = '<select name="survey_id" id="survey_id" onchange="changeSurveySkip(this);">';
		$return .= "<option value=\"0\">-- ".JText::_("COM_SURVEYS_SELECT_SURVEY_FROM_LIST")." --</option>";
		foreach($result as $key=>$value){
			$selected = "";
			if($value["id"] == $default){
				$selected = ' selected="selected" '; 
			}
			$return .= "<option value=\"".$value["id"]."\" ".$selected." >".$value["title"]."</option>";			
		}
		$return .= "</select>";
		return $return;
	}	
	
	function getPageList($default, $survey_id){
		$model = $this->getModel();
		$result = $model->getAllPages($survey_id);
		$return = '<select name="page_id" id="page_id" onchange="changePageSkip(this, \''.$survey_id.'\');">';
		$selected = "";
		foreach($result as $key=>$value){
			$selected = "";
			if($value["id"] == $default){
				$selected = ' selected="selected" '; 
			}
			$return .= "<option value=\"".$value["id"]."\" ".$selected." >".$value["title"]."</option>";			
		}
		$return .= "</select>";
		return $return;
	}
	
	function getQuestionList($default, $survey_id){
		$result = $this->get("AllQuestions");
		$return = '<select name="question_id" id="question_id" onchange="changeQuestionSkip(this, \''.$survey_id.'\');">';
		$selected = "";
		foreach($result as $key=>$value){
			$selected = "";
			if($value["id"] == $default){
				$selected = ' selected="selected" '; 
			}
			$return .= "<option value=\"".$value["id"]."\" ".$selected." >".$value["title"]."</option>";			
		}
		$return .= "</select>";
		return $return;
	}
	
	function getAnswerValues($values, $id){
		$return = "";
		$ids = explode(",", $values);
		if($values == ""){
			return "";
		}
		else{
			$model = $this->getModel('newskip');
			$result = $model->getAnswers($id);			
			if(is_array($result) && count($result)>0){				
				$return .= '<select size="8" multiple="multiple" id="answer_value[]" name="answer_value[]">';
				foreach($result as $key=>$value){
					$selected = '';
					if(in_array($value["id"], $ids)){
						$selected = ' selected="selected" ';
					}
					$return .= '<option '.$selected.' value="'.$value["id"].'">'.$value["value"].'</option>';
				}//foreach
				$return .= "</select>";			
			}//if
		}//else
		return $return;
	}//function
	
	function getPageTarget($id, $page_id, $page_target){
		$return = '<select name="page_target" id="page_target">';
		$model = $this->getModel();
		$pages = $model->getPagesTarget($id, $page_id);
		foreach($pages as $key=>$value){
			$selected = "";
			if($value["id"] == $page_target){
				$selected = ' selected="selected" ';
			}
			$return .= '<option value="'.$value["id"].'" '.$selected.'>'.$value["title"].'</option>';
		}
		$selected = "";
		if($page_target == "-1"){
			$selected = ' selected="selected" ';
		}
		$return .= '<option value="-1"'.$selected.'>'.JText::_("COM_SURVEYS_SURVEY_END").'</option>';
		$return .= "</select>";
		return $return;
	}
}

?>
 